﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace mrp16062010.Veri
{
    class RotaTanim:ConnectionImporter
    {
        private int rotaTanimId;

        public int RotaTanimId
        {
            get { return rotaTanimId; }
            set { rotaTanimId = value; }
        }

        private string ad;

        public string Ad
        {
            get { return ad; }
            set { ad = value; }
        }

        private int stokId;

        public int StokId
        {
            get { return stokId; }
            set { stokId = value; }
        }

        public void Kaydet()
        {
            Connect();
            SqlCommand cmd = new SqlCommand("InsertRotaTanim", Connection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter prmReturnValue = cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
            prmReturnValue.Direction = ParameterDirection.ReturnValue;

            #region Populate Paramete

            SqlParameter prmAd = cmd.Parameters.Add("@Ad", SqlDbType.NVarChar);
            prmAd.Direction = ParameterDirection.Input;
            prmAd.Size = 50;

            prmAd.Value = this.Ad;


            SqlParameter prmStokId = cmd.Parameters.Add("@StokId", SqlDbType.Int);
            prmStokId.Direction = ParameterDirection.Input;

            prmStokId.Value = this.StokId;


            SqlParameter prmRotaTanimId = cmd.Parameters.Add("@RotaTanimId", SqlDbType.Int);


            prmRotaTanimId.Direction = ParameterDirection.Output;


            #endregion


            cmd.ExecuteNonQuery();
            this.RotaTanimId = int.Parse(prmRotaTanimId.Value.ToString());
            cmd.Dispose();
            Disconnect();
        }

        public void Sil()
        {
            Connect();
            SqlCommand cmd = new SqlCommand("DeleteRotaTanim", Connection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter prmRotaTanimId = cmd.Parameters.Add("@RotaTanimId", SqlDbType.Int);
            prmRotaTanimId.Direction = ParameterDirection.Input;
            prmRotaTanimId.Value = this.rotaTanimId;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            Disconnect();
        }

        public void Guncelle()
        {
            Connect();
            SqlCommand cmd = new SqlCommand("UpdateRotaTanim", Connection);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter prmRotaTanimId = cmd.Parameters.Add("@RotaTanimId", SqlDbType.Int);
            prmRotaTanimId.Direction = ParameterDirection.Input;

            prmRotaTanimId.Value = this.RotaTanimId;


            SqlParameter prmAd = cmd.Parameters.Add("@Ad", SqlDbType.NVarChar);
            prmAd.Direction = ParameterDirection.Input;
            prmAd.Size = 50;

            prmAd.Value = this.Ad;


            SqlParameter prmStokId = cmd.Parameters.Add("@StokId", SqlDbType.Int);
            prmStokId.Direction = ParameterDirection.Input;

            prmStokId.Value = this.StokId;




            cmd.ExecuteNonQuery();
            cmd.Dispose();
            Disconnect();
        }

        public void Bul()
        {
            Connect();
            SqlCommand cmd = new SqlCommand("SelectRotaTanim", Connection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter prmRotaTanimId = cmd.Parameters.Add("@RotaTanimId", SqlDbType.Int);
            prmRotaTanimId.Direction = ParameterDirection.Input;
            prmRotaTanimId.Value = this.rotaTanimId;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);

            foreach (DataRow row in dt.Rows)
            {
                this.rotaTanimId = int.Parse(row["RotaTanimId"].ToString());
                this.Ad = row["Ad"].ToString();
                this.stokId = int.Parse(row["StokId"].ToString());
                break;
            }

            cmd.Dispose();
            Disconnect();
        }

        public List<RotaTanim> Listele()
        {
            Connect();
            SqlCommand cmd = new SqlCommand("SelectRotaTanimsAll", Connection);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            List<RotaTanim> liste = new List<RotaTanim>();
            foreach (DataRow row in dt.Rows)
            {
                RotaTanim yeniRotaTanim = new RotaTanim();
                yeniRotaTanim.rotaTanimId = int.Parse(row["RotaTanimId"].ToString());
                yeniRotaTanim.Ad = row["Ad"].ToString();
                yeniRotaTanim.stokId = int.Parse(row["StokId"].ToString());
                liste.Add(yeniRotaTanim);
            }

            cmd.Dispose();
            Disconnect();
            return liste;
        }
        
    }
}
